package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.webserver.request.console.sk.ConsoleSkDeviceListRequest;
import com.mingqijia.gassafety.webserver.request.console.sk.ConsoleSkRecordsRequest;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkAlarmCountResponse;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkDeviceListData;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkDeviceRunStatisticsResponse;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkRecordLogResponse;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkRecordsData;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkRecordsResponse;
import com.mingqijia.gassafety.webserver.service.ConsoleSkAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author solyutian
 * @date 2023/6/27 14:32
 */
@Api(tags = "智慧厨房报警")
@RestController
@RequestMapping("console/sk/v1")
@Slf4j
public class ConsoleSkAlarmController {


  @Autowired
  ConsoleSkAlarmService consoleSkAlarmService;

  /**
   * 查询报警信息列表
   *
   * @param request
   * @return
   */
  @ApiOperation("查询报警信息列表")
  @PostMapping("/alarm/records")
  public CommonResponse<ConsoleSkRecordsData> alarmRecords(@RequestHeader("X-Sp-Id") @ApiParam(value = "spId") String spId, @RequestBody ConsoleSkRecordsRequest request) {
    request.setSpId(spId);
    if (!ObjectUtils.isEmpty(request.getPage())){
      request.setPageNum(request.getPage());
    }
    return consoleSkAlarmService.alarmRecords(request);
  }

  /**
   * 获取工单七日统计
   * @param spId
   * @return
   */
  @ApiOperation("获取工单七日统计")
  @GetMapping("/alarm/recordLog")
  public CommonResponse alarmRecordLogList(@RequestHeader("X-Sp-Id") @ApiParam(value = "spId") String spId) {
    return consoleSkAlarmService.alarmRecordLogList(spId);
  }

  /**
   * 获取当日报警总数
   * @param spId
   * @return
   */
  @ApiOperation("获取当日报警总数")
  @GetMapping("/alarm/alarmCount")
  public CommonResponse alarmAlarmCount(@RequestHeader("X-Sp-Id") @ApiParam(value = "spId")String spId,@RequestHeader("Templatetype") @ApiParam(value = "模板类型 ，1-模板一，2-模板二") Integer templateType) {
    return consoleSkAlarmService.alarmCount(spId,templateType);
  }

  /**
   * 设备运行统计
   * @param spId
   * @return
   */
  @ApiOperation("设备运行统计")
  @GetMapping("/alarm/runStatistics")
  public CommonResponse alarmDeviceRunStatistics(@RequestHeader("X-Sp-Id") @ApiParam(value = "spId") String spId) {
    return consoleSkAlarmService.alarmDeviceRunStatistics(spId);
  }

  /**
   * 设备列表
   * @param spId
   * @return
   */
  @ApiOperation("设备列表")
  @PostMapping("/alarm/deviceList")
  public CommonResponse<ConsoleSkDeviceListData> alarmDeviceList(@RequestHeader("X-Sp-Id") @ApiParam(value = "spId") String spId,@RequestBody ConsoleSkDeviceListRequest request) {
    request.setSpId(spId);
    return consoleSkAlarmService.alarmDeviceList(request);
  }

}
